package com.szit.test.servlet;

import com.szit.test.biz.SaleBiz;
import com.szit.test.biz.impl.SaleBizImpl;
import com.szit.test.entity.Sale;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "DetailServlet",value = "/sys/detail")
public class DetailSaleServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        String sid = request.getParameter("id");
        String edit = request.getParameter("edit");

        if(sid != null && sid != ""){
            int id = Integer.parseInt(sid);

            // 调用逻辑层
            SaleBiz tbiz = new SaleBizImpl();
            Sale teacher = tbiz.search(id);

            // 将集合保存到会话中
            request.setAttribute("t",teacher);
        }

        // 跳转到列表页面
        if(edit!=null && edit.equals("1")) {
            request.getRequestDispatcher("updateteacher.jsp").forward(request,response);
        } else {
            request.getRequestDispatcher("detailteacher.jsp").forward(request,response);
        }
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
